package main

import (
	"encoding/json"
	"flag"
	"fmt"

	"git.oschina.net/dddailing/drsys/backend/model"
	"git.oschina.net/dddailing/drsys/backend/server"
	"github.com/dailing/levlog"
)

func printJson(j interface{}) string {
	body, err := json.MarshalIndent(j, "", "    ")
	levlog.E(err)
	fmt.Println(string(body))
	return string(body)
}

func main() {
	var (
		mysqlHost string
		doc       bool
		test      bool
	)
	flag.StringVar(&mysqlHost,
		"mysqlhost",
		"backend_sql",
		"Setting mysql host.")
	flag.BoolVar(&doc,
		"doc",
		false,
		"Print out doc")
	flag.BoolVar(&test,
		"test",
		false,
		"Is Test")
	flag.Parse()

	if doc {
		printJson(new(model.BinObject))
		return
	}
	var app *server.App
	if test {
		app = server.NewApp(mysqlHost, "test_db")
	} else {
		app = server.NewApp(mysqlHost, server.DB_NAME)
	}
	app.Init()
	levlog.Info("Start")
	app.Run()
}
